<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2018/12/20
 * Time: 下午8:46
 */

namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\Room;
use App\Http\Model\User;
use App\Http\Services\ActivityServices;
use App\Http\Services\MsgServices;
use Illuminate\Support\Facades\Redis;
use App\Http\Services\AnnualCeremonyServices;
use Illuminate\Http\Request;

class ActivityController extends BaseController
{
    protected $activityServices;
    protected $msgService;
    protected $annualCeremonyServices;

    public function __construct()
    {
        $this->activityServices = new ActivityServices();
        $this->msgService = new MsgServices();
        $this->annualCeremonyServices = new AnnualCeremonyServices();
    }

    /**
     * 获取全部开播中的房间
     */
    public function openRoomAll(Request $request)
    {
        $types = $request->input('types', "");
        $data = $this->activityServices->openRoomAll($types);
        OutJson::outJsonResult(Hint::SUCCESS, $data);
    }

    /**
     * 发送活动分享私聊信息
     */
    public function sendShareActivityMsg(Request $request)
    {
        $fromUserId = $request->input('from_user_id', 0);
        $toUserId = $request->input('to_user_id', 0);
        $title = $request->input('title', "");
        $desc = $request->input('desc', "");
        $image = $request->input('image', "");
        $url = $request->input('url', "");

        if (empty($fromUserId) || empty($toUserId) || empty($title) || empty($desc) || empty($image) || empty($url)) {
            OutJson::outJsonResult(Hint::PARAM_ERROR);
        }

        $this->msgService->sendShareActivityMsgTip($fromUserId, $toUserId, $title,$desc,$image,$url);
        OutJson::outJsonResult(Hint::SUCCESS, []);
    }

    /**
     * 获取用户是否在直播
     * @param Request $request
     */
    public function getUserRoom(Request $request)
    {
         $userIds = $request->input('userIds', '');
         if($userIds == '') {
             OutJson::outJsonResult(Hint::ERROR);
         }
         $userIdArr = explode(',', $userIds);
         $data = $this->annualCeremonyServices->getUserRoom($userIdArr);
         OutJson::outJsonResult(Hint::SUCCESS, $data);
    }

}
